/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.dbdir.core;

import java.sql.Connection;
import org.dbdir.Server;
import org.dbdir.core.datastore.db.DBManager;

/**
 *
 * @author thotheolh
 */
public class ServerAuth {

    private String connPath = null;
    private String username = null;
    private String password = null;
    private Connection dbConn = null;

    public ServerAuth(String connPath, String username, String password) {
        this.setConnPath(connPath);
        this.setUsername(username);
        this.setPassword(password);
    }

    public ServerAuth() {
    }

    public boolean doAuth() {
        dbConn = new DBManager(getConnPath(), getUsername(), getPassword()).getConnection();
        if (dbConn == null) {
            return false;
        } else {
            new Server().getServerInstance().setDbConn(dbConn);
            return true;
        }
    }

    /**
     * @return the connPath
     */
    public String getConnPath() {
        return connPath;
    }

    /**
     * @param connPath the connPath to set
     */
    public void setConnPath(String connPath) {
        this.connPath = connPath;
    }

    /**
     * @return the username
     */
    public String getUsername() {
        return username;
    }

    /**
     * @param username the username to set
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * @return the dbConn
     */
    public Connection getDbConn() {
        return dbConn;
    }

    /**
     * @param dbConn the dbConn to set
     */
    public void setDbConn(Connection dbConn) {
        this.dbConn = dbConn;
    }
}
